package comply.zyc;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @description:
 * @author: ZhaoYicong
 * @date: Created in 2020/6/22 8:38
 * @version: v1.0
 * @modified By:
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    //创建过滤器，防止页面出现乱码
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置对应的字符集
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=UTF-8");
        //把请求传递给下个
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
